package com.atomos.strategy.emission
{
	import flash.geom.Point;
	
	import com.atomos.particle.MockParticle;
	import com.atomos.particle.Particle;
	
	import flexunit.framework.TestCase;	

	public class AbstractEmissionTest extends TestCase
	{
		protected var _emission : MockAbstractEmission;
		
		public override function setUp():void
		{
			_emission = new MockAbstractEmission ( Particle );
		}
		
		public function testConstruct () : void
		{
			var errorOccurs : Boolean;
			var emission : EmissionStrategy;
			
			assertNotNull ( "Constructor failed to create the instance with a valid Particle's class", _emission );
			
			errorOccurs = false;
			try
			{
				emission = new MockAbstractEmission ( null );
			}
			catch ( e : Error )
			{
				errorOccurs = true;
			}
			assertTrue( "Constructor don't failed when passing a null Particle's class", errorOccurs );
			
			
			errorOccurs = false;
			try
			{
				emission = new MockAbstractEmission ( Point );
			}
			catch ( e : Error )
			{
				errorOccurs = true;
			}
			assertTrue( "Constructor don't failed when passing an invalid Particle's class", errorOccurs );
			
			errorOccurs = false;
			try
			{
				emission = new AbstractEmission ( Particle );
			}
			catch ( e : Error )
			{
				errorOccurs = true;
			}
			assertTrue( "Constructor don't failed when a subclass don't implements one of the virtual methods", errorOccurs );
		}
		
		public function testNext () : void
		{
			var p : Particle = _emission.next() as Particle;
			
			assertNotNull ( _emission + ".next() return a null particle", p ); 
		}
		
		public function testGetSetType () : void
		{
			var errorOccurs : Boolean;
			
			_emission.setParticleType( MockParticle );
			
			assertEquals ( _emission + ".setParticleType() failed with a valid Particle class", MockParticle ,_emission.getParticleType() );
			
			errorOccurs = false;
			try
			{
				_emission.setParticleType( null );
			}
			catch ( e : Error )
			{
				errorOccurs = true;
			}
			assertTrue( _emission + ".setParticleType() don't failed when passing a null Particle's class", errorOccurs );
			
			errorOccurs = false;
		
			try
			{
				_emission.setParticleType ( Point );
			}
			catch ( e : Error )
			{
				errorOccurs = true;
			}
			assertTrue( "Constructor don't failed when passing an invalid Particle's class", errorOccurs );
		}
		
		public function testGetSetPosition () : void
		{
			assertNotNull ( _emission + " constructor failed to defined a default position", _emission.getPosition() );
			
			_emission.setPosition( null );
			
			assertNotNull ( _emission + ".setPosition() failed with null as argument", _emission.getPosition() );
			
			var p : Point = new Point( 5, 5 );
			_emission.setPosition( p );
			
			assertNotNull ( _emission + ".setPosition() failed with a valid point as argument", _emission.getPosition() );
			assertEquals ( _emission + ".getPosition() don't return the previously added point", p, _emission.getPosition() );			
		}
	}
}